/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t__sqlserver_set_analysis_data.c                   */
/*  NOTE      =                                                    */
/*  DATE      = 2015/01/20 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

int __sqlserver_set_analysis_data(L7session_sqlserver_private *p_st_private, char *p_data, unsigned int ui_len,
                                  struct timeval *p_st_timestamp, uint8_t *p_u8_data_type, int *p_i_cancel_flg,
                                  int *p_i_whole_flg);

static void __case1(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x04\x00\x00\x09\x00\x00\x00\x00", 8);
    unsigned int ui_len = 8;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 9);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;

}

static void __case2(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x09\x00\x00\x00", 4);
    unsigned int ui_len = 4;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    memcpy(p_st_fragment->arr_residual_packet_head, "\x04\x00\x00", 3);
    p_st_fragment->i_residual_packet_head_len = 3;
    p_st_fragment->p_st_data = bytebuff_creat();

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 0);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x04\x00\x00\x09\x00\x00\x00", 7) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 0);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;

}

static void __case3(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x09\x00\x00\x00\x00", 5);
    unsigned int ui_len = 5;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    memcpy(p_st_fragment->arr_residual_packet_head, "\x04\x00\x00", 3);
    p_st_fragment->i_residual_packet_head_len = 3;
    p_st_fragment->p_st_data = bytebuff_creat();

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x04\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 9);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 0);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;

}

static void __case4(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x04\x00\x00\x09\x00\x00\x00\x00", 8);
    unsigned int ui_len = 8;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 1;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 9);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

static void __case5(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x04\x03\x00\x09\x00\x00\x00\x00", 8);
    unsigned int ui_len = 8;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_YES);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 9);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 1);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

static void __case6(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x04\x01\x00\x08\x00\x00\x00\x00", 8);
    unsigned int ui_len = 8;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_YES);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 8);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

static void __case7(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x04\x00\x00\x09\x00\x00\x00\x00\x01\x04\x00\x00\x09\x00\x00\x00\x00\x01", 18);
    unsigned int ui_len = 18;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;
    Frbyte_buffer *p_byte_buff = NULL;
    Frlist_node *p_st_node = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;

    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 4);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_NO);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 18);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_first_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 2);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 2);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    p_st_node = FRLIST_FIRST_NODE(p_st_data->p_lst_bytebuffer);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 1);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x01", 1) == 0);

    p_st_node = FRLIST_NEXT_NODE(p_st_node);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 1);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x01", 1) == 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

static void __case8(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x00\x00\x00\x00\x00\x03\x00", 7);
    unsigned int ui_len = 7;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;
    Frbyte_buffer *p_byte_buff = NULL;
    Frlist_node *p_st_node = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;
    p_st_fragment->i_end_packet_flg = FR_YES;
    p_st_fragment->ui_total_len = 8;
    p_st_fragment->ui_remain_len = 5;
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x01\x02\x03", 3);
    p_st_fragment->p_st_data = p_st_data;


    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 0);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_YES);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x03\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 8);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_end_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_end_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 8);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 8);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    p_st_node = FRLIST_FIRST_NODE(p_st_data->p_lst_bytebuffer);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 3);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x01\x02\x03", 3) == 0);

    p_st_node = FRLIST_NEXT_NODE(p_st_node);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 5);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x00\x00\x00\x00\x00", 5) == 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

static void __case9(void)
{
    int i_ret = 0;
    L7session_sqlserver_private *p_st_private = NULL;
    char *p_data = (char *) frmemdup("\x00\x00\x00\x00\x00", 5);
    unsigned int ui_len = 5;
    struct timeval st_timestamp;
    uint8_t u8_data_type = 0;
    int i_cancel_flg = FR_NO;
    int i_whole_flg = FR_NO;
    L7_fragment_sqlserver *p_st_fragment = NULL;
    Frbyte_Packet *p_st_data = NULL;
    Frbyte_buffer *p_byte_buff = NULL;
    Frlist_node *p_st_node = NULL;

    p_st_private = (L7session_sqlserver_private *) frmalloc(sizeof(L7session_sqlserver_private));
    memset(p_st_private, 0x00, sizeof(L7session_sqlserver_private));

    p_st_fragment = (L7_fragment_sqlserver *) frmalloc(sizeof(L7_fragment_sqlserver));
    memset(p_st_fragment, 0x00, sizeof(L7_fragment_sqlserver));
    sqlserver_init_fragment(p_st_fragment);
    p_st_private->p_st_fragment = p_st_fragment;
    p_st_fragment->i_end_packet_flg = FR_YES;
    p_st_fragment->ui_total_len = 8;
    p_st_fragment->ui_remain_len = 5;
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *) "\x01\x02\x03", 3);
    p_st_fragment->p_st_data = p_st_data;


    st_timestamp.tv_sec = 1000;
    st_timestamp.tv_usec = 500;

    i_ret = __sqlserver_set_analysis_data(p_st_private, p_data, ui_len, &st_timestamp, &u8_data_type, &i_cancel_flg,
                                          &i_whole_flg);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(u8_data_type, 0);
    CU_ASSERT_EQUAL(i_cancel_flg, FR_NO);
    CU_ASSERT_EQUAL(i_whole_flg, FR_YES);
    p_st_fragment = p_st_private->p_st_fragment;

    CU_ASSERT_TRUE(memcmp(p_st_fragment->arr_residual_packet_head, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0);
    CU_ASSERT_EQUAL(p_st_fragment->ui_total_len, 8);
    CU_ASSERT_EQUAL(p_st_fragment->ui_remain_len, 0);
    CU_ASSERT_EQUAL(p_st_fragment->st_end_timestamp.tv_sec, 1000);
    CU_ASSERT_EQUAL(p_st_fragment->st_end_timestamp.tv_usec, 500);

    p_st_data = p_st_fragment->p_st_data;
    CU_ASSERT_EQUAL(p_st_data->pos_index, 0);
    CU_ASSERT_EQUAL(p_st_data->ui_all_len, 8);
    CU_ASSERT_EQUAL(p_st_data->ui_remaining, 8);
    CU_ASSERT_EQUAL(p_st_data->ui_skip_len, 0);

    p_st_node = FRLIST_FIRST_NODE(p_st_data->p_lst_bytebuffer);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 3);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x01\x02\x03", 3) == 0);

    p_st_node = FRLIST_NEXT_NODE(p_st_node);
    p_byte_buff = (Frbyte_buffer *) p_st_node->data;
    CU_ASSERT_EQUAL(p_byte_buff->pos, 0);
    CU_ASSERT_EQUAL(p_byte_buff->ui_len, 5);
    CU_ASSERT_TRUE(memcmp(p_byte_buff->p_buf, "\x00\x00\x00\x00\x00", 5) == 0);

    frfree(p_data);
    bytebuff_free(&(p_st_fragment->p_st_data));
    frfree(p_st_fragment);
    frfree(p_st_private);

    return;
}

int add_suite__sqlserver_set_analysis_data(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __sqlserver_set_analysis_data()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL ||
        CU_add_test(pSuite, "case8", __case8) == NULL ||
        CU_add_test(pSuite, "case9", __case9) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
